## noaaDataToShp.py
## This file imports NOAA sea level rise vectors and saves them as shape files so we can extract coordinates and polygons from them.
## The raw NOAA sea level rise vectors come from https://coast.noaa.gov/slrdata/Sea_Level_Rise_Vectors/index.html, originally retrieved in August 2020 for each state listed above. We downloaded the `state'_slr_data_dist.zip files for each state.
## You will have to change the file paths of where the raw data is saved and where the output data is stored in order to run this

## Versions of the same code for each foot of SLR (0ft, 1ft, ..., 6ft):

# 0 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

# Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# Each state's NOAA data is saved in a different folder in this raw_slr_data folder
# This loops through each state to convert the .gdb data for 0 feet of SLR to a shape file and save it in the 0ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_0ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/0ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/0ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')

# 1 foot
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 1 feet of SLR to a shape file and save it in the 1ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_1ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/1ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/1ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')
            
# 2 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 2 feet of SLR to a shape file and save it in the 2ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_2ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/2ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/2ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')
            
# 3 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 3 feet of SLR to a shape file and save it in the 3ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_3ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/3ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/3ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')
            
# 4 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 4 feet of SLR to a shape file and save it in the 4ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_4ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/4ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/4ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')
            
            
# 5 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 5 feet of SLR to a shape file and save it in the 5ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_5ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/5ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/5ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')
            
# 6 feet
# Script to import US layers from NOAA SLR file geodatabases and export as shapefiles so they can be used outside of ArcGIS
import arcpy, glob, os, re, time
start_time=time.time()
arcpy.env.addOutputstoMap=True

#Get all geodatabases in US using wildcard
path="X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/input_data/raw_slr_data/*"
raw_data=glob.glob(path)

# This loops through each state to convert the .gdb data for 6 feet of SLR to a shape file and save it in the 6ft folder
for statepath in raw_data:
    pathtogdb=statepath+"/*dist"+"/*gdb"
    regionpath=glob.glob(pathtogdb)
    for filename in regionpath:
        arcpy.env.workspace=filename
        regionfeatureclasses=arcpy.ListFeatureClasses(wild_card="*slr_6ft")
        if filename==regionpath[0]:
            arcpy.management.Merge(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/6ft/"+statepath[-2:])
        else:
            #Use "NO_TEST" option because appending different data types (raw data are file geodatabase feature classes and slr.shp is shapefile feature class)
            arcpy.management.Append(regionfeatureclasses, "X:/RE.E1D/Secure Folders - Economist/Corelogic-Phan/SLR/Maps/output_shapefiles/6ft/"+statepath[-2:]+".shp", schema_type='NO_TEST')